//
//  MyReplyViewController.m
//  心水宝典
//
//  Created by zr on 2018/8/31.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "MyReplyViewController.h"
#import "MyReplyTableViewCell.h"
#import "MyReplyModel.h"

@interface MyReplyViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, weak)UITableView * tableView;
@property (nonatomic, strong)NSMutableArray <MyReplyModel *> * modelArray;


@end

@implementation MyReplyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = WHITE_COLOR;
    self.modelArray = [NSMutableArray array];
    
    [self loadData];
    [self setupNav];
    [self setupUI];
}

- (void)loadData{
    
    NSString * token = DEF_GET_OBJECT(@"token");
    NSString * url = [NSString stringWithFormat:@"/api/member/comment?type=1&project_id=1&token=%@",token];
    
    [[NetworkTool sharedTools] GET:url parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *  _Nullable responseObject) {
        
        NSArray *array = [NSArray yy_modelArrayWithClass:[MyReplyModel class] json:responseObject[@"data"]];
        [self.modelArray addObjectsFromArray:array];
        [self.tableView reloadData];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        NSLog(@"errror===%@",error);
    }];
    
}

- (void)setupNav{
    
    self.title = @"我的回复";
    
    UIButton * backButton = [[UIButton alloc] init];
    
    //    backButton.frame = CGRectMake(0, 0, 20 * SCREENH6, 20 * SCREENH6);
    backButton.size = CGSizeMake(20 * SCREENH6, 20 * SCREENH6);
    [backButton setImage:[UIImage imageNamed:@"fanhui"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backToView) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.navigationItem.leftBarButtonItem = leftButton;
}



- (void)setupUI{
    
    UITableView * tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREENH_HEIGHT - 64) style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.backgroundColor = [UIColor whiteColor];
    tableView.rowHeight = 95 * SCREENH6;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    if (@available(iOS 11.0, *)) {
        tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    self.tableView = tableView;
    
    [self.tableView registerClass:[MyReplyTableViewCell class] forCellReuseIdentifier:@"MyReplyListCell"];
    
    [self.view addSubview:self.tableView];
    
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        
        return self.modelArray.count;
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    MyReplyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyReplyListCell" forIndexPath:indexPath];
    
    cell.model = self.modelArray[indexPath.row];
    
    return cell;
}


- (void)backToView {
    
    [self.navigationController popViewControllerAnimated:YES];
}

@end
